package sdufe.lele.uitl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import java.util.HashMap;

/**
 * Created by geniee on 17-4-23.
 */
public class Token {


    public static String createToken(String... args) {
        HashMap<String, String> map = new HashMap<>();

        for (int i = 0; i < args.length; i += 2) {
            map.put(args[i], args[i + 1]);
        }

        return DigestUtil.Encrypt(JSON.toJSONString(map));

    }

    public static HashMap<String,String> decryptToken(String token) {
        try {
            String decoded = DigestUtil.Decrypt(token);
            return JSON.parseObject(decoded, new  TypeReference<HashMap<String, String>>() {});
        } catch (IllegalArgumentException ex) {
            System.out.println("不是合法的token");
        }
        return null;
    }


}
